<?php
	
	 error_reporting(E_ALL);
?> 
 
<script>
function printData(){
window.print();
}
	
	function reloadPage(){	
		var karyawan_id =$("#karyawan_id").val();	
		$("#tblData").jqGrid("setGridParam",{postData:{"karyawan_id" :karyawan_id},datatype:"json"}).trigger("reloadGrid",[{current:true}]);
	} 
	function editRow(id,karyawan_id){		
		var url="index.php?r=karyawan/home/form&op=edit&id=" + id +"&karyawan_id=" + karyawan_id;
		var winName = "Edit";
		var specs ="menubar=0,scrollbars=1,status=0,titlebar=0,toolbar=0";
		var width=800,height=600;
		var replace = true,onCenter = true;
		var w = openWindow(winName,url,width,height,onCenter,specs,replace);
		w.focus();
		var timer = setInterval(function() {   
			if(w.closed) {  
				clearInterval(timer);  
				reloadPage();
			}  
		}, 1000);
	}	
	  
$(function(){
		var karyawan_id =$("#karyawan_id").val();	
		var numberTemplate = {formatter: 'number', align: 'right', sorttype: 'number'};	 
		$("#tblData").jqGrid({
			url:'index.php?r=karyawan/home/detailList',
			datatype: 'json',
			loadonce:true,
			mtype:"GET",
			autowidth:true,
			height:"100%",
			altRows:true,
			ignoreCase:true,
			colNames: ['','Create Date','Student ID','Student Name',  'Title Message','','','notes' ],
			colModel: [
				{name: 'id', index: 'id', width: 40,hidden:true,sorttype:'int',formatter:'int'},
				{name: 'create_date', index: 'create_date', formatter : 'date', formatoptions : {newformat : 'd M Y'},width: 50 },				 
				{name: 'sid', index: 'sid', width: 50 },				 				
				{name: 'name', index: 'name', width: 80,search:true},
				{name: 'subject', index: 'subject', width: 150,search:true},		
				{name: 'last_sender', index: 'subject', width: 150,search:true,hidden:true},	
				{name: 'read_status', index: 'subject', width: 150,search:true,hidden:true},												
				{name: 'act', index: 'act', width: 40, align: 'center'},
				 			
			],
			gridview: true,
			rownumbers: false,
			rowNum: 10,
			rowList: [10, 20, 30],
			pager: '#navTblData',
			viewrecords: true,	
			caption: 'Commbook Student',
			jsonReader : { 
				root:"model",
				repeatitems: false			
			},
			loadComplete:function(data){
				console.log(data);
			},
			gridComplete: function(){ 
				var ids = jQuery("#tblData").getDataIDs(); 
				for(var i=0;i<ids.length;i++){ 
					var cl = ids[i]; 
				    var last_sender = jQuery('#tblData').getCell(cl, 'last_sender'); 		
				    var read_status = jQuery('#tblData').getCell(cl, 'read_status'); 					
					if ((last_sender=="Parent")&&(read_status==1)) {  var newstat="new"; } else { var newstat="";}
					//btnEdit = "<input style='height:22px;width:20px;' type='button' value='E' onclick=jQuery('#rowed2').editRow("+cl+"); ></ids>"; 
					//btnDelete = "<input style='height:20px;width:20px;' type='button' value='S' onclick=jQuery('#rowed2').saveRow("+cl+"); />"; 
					btnEdit = "<img title='edit' class='imgBtn' style='height:20px;width:20px;' src='images/action/Actions-Edit-icon.png' onclick='editRow(" + cl + ","+ karyawan_id +")' />" + newstat; 
					jQuery("#tblData").setRowData(ids[i],{act:btnEdit}) 
				} 
			}			 
		});
		$("#tblData").jqGrid('navGrid','#navTblData',{add:false,edit:false,search:false,del:false,refresh:false});
		
		//add search text
		$("#tblData").jqGrid('addSearchText',["name","subject"]);
 	
	});
 
</script> 
    <input type="hidden" id="karyawan_id" name="karyawan_id" value="<?php echo $karyawan_id ?>"  />

<div style="float:rigth">&nbsp;
<?php 
    $this->widget('application.components.widgets.ActionBar', 
        array("menuAlign" => "right", 
            'items' => array(
                array(
                    'id' => "btnRefresh",
                    'title' => Yii::t("menu","Segarkan"),
                    'icon' => "images/action/Action-Refresh-icon.png",
                    'callback'=>"reloadPage"
                ),	  		
           /*     array(
                    'id' => "btnNew",
                    'title' => Yii::t("menu","Tambah"),
                    'icon' => "images/action/Actions-document-new-icon.png",
                    'callback'=>"newData"
                ),   
                array(
                    'id' => "btnNew",
                    'title' => Yii::t("menu","Cetak"),
                    'icon' => "images/action/Actions-document-print-icon2.png",
                    'callback'=>"printData"
                ),					
                 */
            ) 
        )
    );
?>
</div>	    
<div style="">
	<table id="tblData"><tr></tr></table>
	<div id="navTblData"></div>
 </div>

 